/*
Copyright 2011 Raymond Giorgi

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 */

package edu.pitt.cs3530.xml;

import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;

public class ApplicationServerHandler implements ContentHandler {

	public class ConfigObject {
		String fullServerName;
		String serverName;
		int port;
		long utilCheckTimeout;
		long utilSendTimeout;
		String hwaddrLocation;

		private ConfigObject() {
		}

		public String getFullServerName() {
			return this.fullServerName;
		}

		public String getServerName() {
			return this.serverName;
		}

		public int getPort() {
			return this.port;
		}

		public long getUtilCheckTimeout() {
			return this.utilCheckTimeout;
		}

		public long getUtilSendTimeout() {
			return this.utilSendTimeout;
		}

		public String getHwaddrLocation() {
			return this.hwaddrLocation;
		}
	}

	private ConfigObject configObject = new ConfigObject();

	public ConfigObject getConfigObject() {
		return this.configObject;
	}

	@Override
	public void characters(char[] arg0, int arg1, int arg2) throws SAXException {
		// TODO Auto-generated method stub

	}

	@Override
	public void endDocument() throws SAXException {
		// TODO Auto-generated method stub

	}

	@Override
	public void endElement(String arg0, String arg1, String arg2)
			throws SAXException {
		// TODO Auto-generated method stub

	}

	@Override
	public void endPrefixMapping(String arg0) throws SAXException {
		// TODO Auto-generated method stub

	}

	@Override
	public void ignorableWhitespace(char[] arg0, int arg1, int arg2)
			throws SAXException {
		// TODO Auto-generated method stub

	}

	@Override
	public void processingInstruction(String arg0, String arg1)
			throws SAXException {
		// TODO Auto-generated method stub

	}

	@Override
	public void setDocumentLocator(Locator arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void skippedEntity(String arg0) throws SAXException {
		// TODO Auto-generated method stub

	}

	@Override
	public void startDocument() throws SAXException {
		// TODO Auto-generated method stub

	}

	@Override
	public void startElement(String arg0, String arg1, String arg2,
			Attributes arg3) throws SAXException {
		String value = arg3.getValue("value");
		if (arg2.equals("front-end-full-path")) {
			configObject.fullServerName = value;
		} else if (arg2.equals("front-end-name")) {
			configObject.serverName = value;
		} else if (arg2.equals("front-end-port")) {
			configObject.port = Integer.parseInt(value);
		} else if (arg2.equals("utilization-check-sleep")) {
			configObject.utilCheckTimeout = Long.parseLong(value);
		} else if (arg2.equals("utilization-send-sleep")) {
			configObject.utilSendTimeout = Long.parseLong(value);
		} else if (arg2.equals("hwaddr-file")) {
			configObject.hwaddrLocation = value;
		}
	}

	@Override
	public void startPrefixMapping(String arg0, String arg1)
			throws SAXException {
		// TODO Auto-generated method stub

	}

}
